package com.example.base_kotlin_xml.model.source

import com.example.base_model.api.ApiService
import com.example.base_model.bean.BaseHttpBean
import com.example.base_model.bean.general.TestRequest
import com.squareup.moshi.JsonDataException
import javax.inject.Inject
import javax.inject.Singleton

/**
 * @Author jiangKunKun
 * @CreateDate 2025/8/6
 * @Description
 * @SpittingGrooves
 */
@Singleton
class TestRemoteDataSource @Inject constructor(
    private val apiService: ApiService
) : TestDataSource {

    override suspend fun getAisleCode(code: String): BaseHttpBean<String> {
        return apiService.aisleCode(code)
    }

    override suspend fun getBeanList(requests: List<TestRequest>): BaseHttpBean<List<TestRequest>> {
        return try {
            val response = apiService.beanList(requests)
            response
        } catch (e: JsonDataException) {
            // 处理解析错误，返回适当的默认值
            BaseHttpBean(
                code = -1,
                msg = "Data format error: ${e.message}",
                data = emptyList()
            )
        }
    }
}